package com.financing.wap;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.stereotype.Service;

import com.financing.wap.config.ConfigurationLoaderUtil;

@Service
//public class StartupListenerForProperties implements ApplicationListener<ContextRefreshedEvent> {
public class StartupListenerForProperties implements SmartApplicationListener {
	
	
	final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	private volatile boolean isOnEvent = false ; //是否已经执行过 onApplicationEvent () 方法
	
	/**
	 * 启动应用服务器时，加载sfa.properties文件，动态获得系统级的配置信息
	 */
	private void loadSFAProperties() {

			System.out.println("支付配置参数");
			
			//加载配置参数
			ConfigurationLoaderUtil.change2Beans();
			
			
	}
	
	
	@Override
	public void onApplicationEvent(ApplicationEvent arg0) {

		if( !isOnEvent ){
			if( logger.isInfoEnabled() ){
				logger.info("启动时加载系统参数.....................");
			}
			
			loadSFAProperties();
			

			if( logger.isInfoEnabled() ){
				logger.info("加载系统参数对象成功 .......");
			}
			isOnEvent = true ; //已经执行
		}
	}

	@Override
	public int getOrder() {
		return 0;//最先加载系统参数表
	}

	@Override
	public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
		return true ; 
	}

	@Override
	public boolean supportsSourceType(Class<?> sourceType) {
		return true ; 
	}
	
}
